package com.animal.controller;

import javax.servlet.http.HttpServletRequest;
import com.animal.dao.ExpManage;

public class PageServlet_exp {

	public int intCountTopic=0;    // 记录总数
	public int intPageSize;        // 每页显示记录数
	public int intPageCount=0;     // 总页数
	public int intPage = 1;        // 当前页数,初始化当前页intPage变量，以准确便获取当前页
	public String nowPage;         // 当前页码
	public String HttpFile;        //当前的地址栏的文件
	
	public PageServlet_exp() {
		intPageSize = 7; // 每页显示的记录数目
	}

	// request :参数传递过程中的变量。[用来控制翻页时的pages变量]
	public void page(HttpServletRequest request) throws Exception {
		
		HttpFile = request.getRequestURI();      // 获取当前文件名
		nowPage = request.getParameter("pages"); // 获取当前页，将数值赋予intPage变量
		if (nowPage == null) {
			intPage = 1;
		} else {
			intPage = Integer.parseInt(nowPage);
			if (intPage < 1)
				intPage = 1;
		}	
		intCountTopic = ExpManage.selectNum(); // 获取总记录数的结果集
		intPageCount = (intCountTopic + intPageSize - 1) / intPageSize; // 获取总页数
		if (intPage > intPageCount)  // 如果当前页大于总页数，则当前页等于总页数
		{
			intPage = intPageCount;
		}
	}
	
	//构造页签
	public String PageFooter() {
		String str = "";
		int next, prev;
		prev = intPage - 1;
		next = intPage + 1;
		str += "查询到<font color=red>" + intCountTopic + "</font>条记录"
				+ "&emsp;&emsp;共<font color=red>" + intPageCount + "</font>页";
		str += "&emsp;&emsp;第<font color=red>" + intPage + "</font>页 ";
		if (intPage > 1)
			str += "&emsp;&emsp;<A href=" + HttpFile + "?pages=1" + ">首页</A> ";
		else
			str += "&emsp;&emsp;首页 ";
		if (intPage > 1)
			str += "&emsp;&emsp;<A href=" + HttpFile + "?pages=" + prev + ">上一页</A> ";
		else
			str += "&emsp;&emsp;上一页 ";
		if (intPage < intPageCount)
			str += "&emsp;&emsp;<A href=" + HttpFile + "?pages=" + next + ">下一页</A> ";
		else
			str += "&emsp;&emsp;下一页 ";
		if (intPageCount > 1 && intPage != intPageCount)
			str += "&emsp;&emsp;<A href=" + HttpFile + "?pages=" + intPageCount+ ">尾页</A>";
		else
			str += "&emsp;&emsp;尾页 ";

		return str;
	}
	
	
	
}
